<%@ page import="bcared.*"%>
<% 
String username =  request.getParameter("username");

String firstname = null;
String lastname = null;
String customername = null;
int userid = 0;
String rolename = null;
int roleid = 0;
int customerid =0;

ValidUser u = new ValidUser();
u.setUserName(username);
String password = u.getPassword();
u.setPassword(password);
rolename=u.getRoleName();
roleid=u.getRoleId();
userid=u.getUserId();
u.closeConnection();

if (rolename.equals("None"))  {
  response.sendRedirect("logonerror.jsp"); 
 	return ;
}

session.setAttribute("roleid",roleid + "");
session.setAttribute("rolename",rolename);
session.setAttribute("userid",userid +"");
session.setAttribute("username",username +"");

if (rolename.equals("Customer") || roleid==4 || roleid==5 || roleid==1 || roleid==3) {

Customer c = new Customer(u.getCustomerID());

customerid = c.getCustomerid();
System.out.println("" +customerid);
firstname = c.getFirstname();
lastname = c.getLastname();
customername = c.getCustomername();
session.setAttribute("customerid",customerid + "");
session.setAttribute("firstname",firstname);
session.setAttribute("lastname",lastname);
session.setAttribute("customername",customername);
c.closeConnection();

	switch (roleid) {
        case 1:  response.sendRedirect("CSRhomepage.jsp");  
        	     break; // admin/csr TODO
        case 2:  response.sendRedirect("customerhome.jsp");     
        		 break; // customer
        case 3:  response.sendRedirect("dispatchhome.jsp");        
        		 break; // dispatcher
        case 4:  response.sendRedirect("EngineerHome.jsp?userid="+userid+"&msgid=0");        
        		 break; // engineer
        case 5:  response.sendRedirect("EngineerHome.jsp?userid="+userid+"&msgid=0");         
        		 break; // remote engineer	              	
        default: roleid = 0; break;
    }


}

%>




